import type { PaginationProps } from '@pureadmin/table'
import { computed, reactive } from 'vue'

export function usePagination(onChange?: () => void) {
  const pagination = reactive<PaginationProps>({
    total: 0,
    pageSize: 10,
    currentPage: 1,
    background: true,
  })
  const paginationParams = computed<HttpPaginationParams>(() => ({
    pageNum: pagination.currentPage,
    pageSize: pagination.pageSize,
  }))

  function changePageSize(val: number) {
    pagination.currentPage = 1
    pagination.pageSize = val
    onChange?.()
  }

  function changePageNumber(val: number) {
    pagination.currentPage = val
    onChange?.()
  }

  return { pagination, paginationParams, changePageNumber, changePageSize }
}
